﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using BKIUS;
using BKIDS.CDBNames;
using BKIDS;
using IP.Core.IPCommon;
using IP.Core.IPData;

public partial class ChucNang_F610_Assign_thanh_vien_du_an : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_ten_du_an_2_combo_du_an_list();
            load_ten_tv_2_lst();
            load_ten_tv_2_lst_tv_da();
        }
    }

    #region Members
        
    #endregion

    #region Private Methods
    // 
    private void load_ten_tv_2_lst()
    {
        try
        {
            US_V_DM_THANH_VIEN v_us_thanh_vien = new US_V_DM_THANH_VIEN();
            DS_V_DM_THANH_VIEN v_ds_thanh_vien = new DS_V_DM_THANH_VIEN();
            v_us_thanh_vien.FillDataset(v_ds_thanh_vien," WHERE ID NOT IN (SELECT ID_THANH_VIEN FROM DM_THANH_VIEN_DU_AN WHERE ID_DU_AN =" + CIPConvert.ToDecimal(m_cbo_du_an.SelectedValue) + ")");

            lst_ds_thanh_vien.DataTextField = V_DM_THANH_VIEN.TEN_DAY_DU;
            lst_ds_thanh_vien.DataValueField = V_DM_THANH_VIEN.ID;
            lst_ds_thanh_vien.DataSource = v_ds_thanh_vien.V_DM_THANH_VIEN;
            lst_ds_thanh_vien.DataBind();
        }
        catch (Exception v_e)
        {
            
        }
    }

    private void load_ten_tv_2_lst_tv_da()
    {
        try
        {
            US_V_DM_THANH_VIEN v_us_thanh_vien = new US_V_DM_THANH_VIEN();
            DS_V_DM_THANH_VIEN v_ds_thanh_vien = new DS_V_DM_THANH_VIEN();
            v_us_thanh_vien.FillDataset(v_ds_thanh_vien, " WHERE ID IN (SELECT ID_THANH_VIEN FROM DM_THANH_VIEN_DU_AN WHERE ID_DU_AN =" + CIPConvert.ToDecimal(m_cbo_du_an.SelectedValue) + ")");

            lst_da_thanh_vien_da.DataTextField = V_DM_THANH_VIEN.TEN_DAY_DU;
            lst_da_thanh_vien_da.DataValueField = V_DM_THANH_VIEN.ID;
            lst_da_thanh_vien_da.DataSource = v_ds_thanh_vien.V_DM_THANH_VIEN;
            lst_da_thanh_vien_da.DataBind();
        }
        catch (Exception v_e)
        {
           
        }
    }

    private void load_ten_du_an_2_combo_du_an_list()
    {
        US_DM_DU_AN v_us_du_an = new US_DM_DU_AN();
        DS_DM_DU_AN v_ds_du_an = new DS_DM_DU_AN();

        v_us_du_an.FillDataset(v_ds_du_an, " WHERE ID_TRANG_THAI_DU_AN <> 540");

        m_cbo_du_an.DataTextField = DM_DU_AN.TEN_DU_AN;
        m_cbo_du_an.DataValueField = DM_DU_AN.ID;
        m_cbo_du_an.DataSource = v_ds_du_an.DM_DU_AN;
        m_cbo_du_an.DataBind();
    }
    #endregion

    #region Public Interfaces
  
    #endregion
    protected void m_cbo_du_an_SelectedIndexChanged(object sender, EventArgs e)
    {
        load_ten_tv_2_lst();
        load_ten_tv_2_lst_tv_da();
        m_lbl_thong_bao.Text = "";
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        try
        {
            if (lst_ds_thanh_vien.SelectedItem == null)
                m_lbl_thong_bao.Text = "(*) Bạn chưa chọn thành viên để thêm vào dự án.";
            while (lst_ds_thanh_vien.Items.Count > 0 && lst_ds_thanh_vien.SelectedItem != null)
            {
                ListItem selectedItem = lst_ds_thanh_vien.SelectedItem;
                selectedItem.Selected = false;
                lst_da_thanh_vien_da.Items.Add(selectedItem);
                lst_ds_thanh_vien.Items.Remove(selectedItem);
                m_lbl_thong_bao.Text = "";
            }

        }
        catch (Exception v_e)
        {
            
        }
    }
    protected void m_lbt_xoa_Click(object sender, EventArgs e)
    {
        try
        {
            if (lst_da_thanh_vien_da.SelectedItem == null)
                m_lbl_thong_bao.Text = "(*) Bạn chưa chọn thành viên để xóa khỏi dự án.";
            while (lst_da_thanh_vien_da.Items.Count > 0 && lst_da_thanh_vien_da.SelectedItem != null)
            {
                ListItem selectedItem = lst_da_thanh_vien_da.SelectedItem;
                selectedItem.Selected = false;
                lst_ds_thanh_vien.Items.Add(selectedItem);
                lst_da_thanh_vien_da.Items.Remove(selectedItem);
                m_lbl_thong_bao.Text = "";
            }

        }
        catch (Exception v_e)
        {

        }
    }
    protected void m_cmd_cap_nhat_Click(object sender, EventArgs e)
    {
        try
        {
            m_lbl_thong_bao.Text = "";
            string v_str_id_thanh_vien = "";
            foreach (ListItem ltTemp in this.lst_da_thanh_vien_da.Items)
            {
                v_str_id_thanh_vien += ltTemp.Value + ",";
            }
            US_DM_THANH_VIEN_DU_AN v_us_thanh_vien_du_an = new US_DM_THANH_VIEN_DU_AN();
            v_us_thanh_vien_du_an.update_thanh_vien_du_an(CIPConvert.ToDecimal(m_cbo_du_an.SelectedValue), v_str_id_thanh_vien);
            m_lbl_thong_bao.Text = "Cập nhật thành công !";
        }
        catch (Exception v_e)
        {
            Response.Write(v_e.Message);
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        try
        {
            m_lbl_thong_bao.Text = "";
            foreach (ListItem ltTemp in this.lst_ds_thanh_vien.Items)
            {
                this.lst_da_thanh_vien_da.Items.Add(ltTemp);
            }
            this.lst_ds_thanh_vien.Items.Clear();
        }
        catch (Exception v_e)
        {
            
        }
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        try
        {
            m_lbl_thong_bao.Text = "";
            foreach (ListItem ltTemp in this.lst_da_thanh_vien_da.Items)
            {
                this.lst_ds_thanh_vien.Items.Add(ltTemp);
            }
            this.lst_da_thanh_vien_da.Items.Clear();

        }
        catch (Exception v_e)
        {
           
        }
    }
}